//
//  LXSignRentTableViewCell.h
//  ZuLinProject
//
//  Created by bancheng on 2021/12/20.
//  Copyright © 2021 LX_App. All rights reserved.
//
#import "LXSignRentTableViewCell.h"

@interface LXSignRentTableViewCell ()


@end

@implementation LXSignRentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = White_Color;
        
        [self setClipsToBounds:YES];
        self.titleLab = [[UILabel alloc] init];
        self.titleLab.font = [UIFont systemFontOfSize:16];
        self.titleLab.numberOfLines = 2;
        self.titleLab.textColor = Color333;
        [self.contentView addSubview:self.titleLab];
        [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.contentView.mas_top);
            make.left.equalTo(@15);
            make.width.equalTo(@150);
            make.height.equalTo(self.contentView.mas_height);
        }];
        
        
        
      
         
        self.unit = [[UILabel alloc] init];
        self.unit.font = Fond14
        self.unit.textAlignment = NSTextAlignmentRight;
        self.unit.textColor = Color333;
//        self.unit.numberOfLines = 2;
        self.unit.adjustsFontSizeToFitWidth = YES;
        self.unit.text = @"(总共分0期)";
        [self.contentView addSubview:self.unit];
        [self.unit mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView.mas_right).offset(-15);
            make.width.equalTo(@80);
            make.top.equalTo(self.contentView.mas_top).offset(0);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(0);
         }];
        
        
        
//        self.subTitleLab = [[UILabel alloc] init];
//        self.subTitleLab.numberOfLines = 0;
//        self.subTitleLab.hidden = YES;
//        self.subTitleLab.font = [UIFont systemFontOfSize:16];
//        self.subTitleLab.textAlignment = NSTextAlignmentRight;
//        self.subTitleLab.textColor = UIColor.blackColor;
//        [self.contentView addSubview:self.subTitleLab];
//        [self.subTitleLab mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(self.titleLab.mas_right).offset(10);
//            make.top.equalTo(self.contentView.mas_top);
//            make.right.equalTo(self.contentView.mas_right).offset(-25);
//            make.bottom.equalTo(self.contentView.mas_bottom);
//        }];
        
        
        
        
        self.textFiled = [[UITextField alloc] init];
        self.textFiled.font=[UIFont systemFontOfSize:15];
        self.textFiled.textColor=Color333;
        self.textFiled.placeholder = @"请输入租金金额";
        [self.contentView addSubview:self.textFiled];
        self.textFiled.returnKeyType = UIReturnKeyDone;
        self.textFiled.delegate=self;
        self.textFiled.textAlignment = 2;
        self.textFiled.keyboardType = UIKeyboardTypeDecimalPad;
        [self.textFiled mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLab.mas_right).offset(0);
            make.top.equalTo(self.contentView.mas_top);
            make.right.equalTo(self.unit.mas_left).offset(0);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        
        [self.textFiled addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
        

        
        self.lineV = [[UIView alloc]init];
        self.lineV.backgroundColor = ColorWithF5F5F5;
        [self.contentView addSubview:self.lineV];
        [self.lineV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left);
            make.right.equalTo(self.contentView.mas_right);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-0.5);
            make.height.equalTo(@0.5);
        }];
        
    }
    return self;
}


- (void) textFieldDidChange:(UITextField *) textField{
   
   
    NSString *textString=textField.text;
    
    if(_textfiledChangeBlock)
        _textfiledChangeBlock(textString);
}
- (void)textFieldDidEndEditing:(UITextField *)textField{
    NSString *textString=textField.text;
    
    if ([textString hasSuffix:@"."]) {
        textField.text = [textField.text substringToIndex:textField.text.length-1];
        if(_textfiledChangeBlock)
            _textfiledChangeBlock(textField.text);
        return;
    }
    else {
        if(self.textfiledDidChangeBlock)self.textfiledDidChangeBlock(textString);
    }
}
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    
    NSString *shouldText = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
    NSInteger maxLength= 10;
    
    NSInteger strLength = shouldText.length;
    
    if (strLength > maxLength) {
        // 允许删除
        if (strLength < textField.text.length) {
            return YES;
        }
        
        return NO;
    }
    
    return [NSString validateNumberNegativePoint:shouldText];
    
  
    return YES;
    

}



- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
}

- (void)awakeFromNib {
    [super awakeFromNib];
}


@end
